﻿using System;
using System.Collections.Generic;
using System.Web.Security;
using SouthernLand.Common.DAL.Users;

namespace SouthernLand.Common.BOL.User
{
    public class User : BizObject
    {
        #region Public Properties

        public String UserID { get; set; }

        public String UserName { get; set; }

        public String Password { get; set; }

        public String FirstName { get; set; }

        public String LastName { get; set; }

        public String Gender { get; set; }

        public String BirthDay { get; set; }

        public String Address { get; set; }

        public String Email { get; set; }

        public String Phone { get; set; }

        public String Mobile { get; set; }

        public String Fax { get; set; }

        public Int32 ProvinceID { get; set; }

        public Int32 CountryID { get; set; }

        public String PostalCode { get; set; }

        public String Company { get; set; }

        public String CompanyDescription { get; set; }

        public String EmployeesSize { get; set; }

        public String Website { get; set; }

        public String ImageUrl { get; set; }

        public DateTime AddedDate { get; set; }

        public String AddedBy { get; set; }

        public Boolean IsActive { get; set; }

        #endregion

        #region public static Methods

        public static Boolean UpdateNewsLetter(String Email, Boolean NewsLetter)
        {
            var db = new UserDAL();
            return db.UpdateNewsLetter(Email, NewsLetter);
        }

        public static string EncodePassword(string Password)
        {
            string Format = "MD5";
            return FormsAuthentication.HashPasswordForStoringInConfigFile(Password, Format);
        }

        public static Boolean CheckUserName(String UserName)
        {
            var db = new UserDAL();
            return db.CheckUserName(UserName);
        }

        /// <summary>
        /// Phan nay Search dung cho Admin
        /// </summary>
        public static List<User> AdminSearch(String Keyword, String RoleName)
        {
            // keyword = null và RoleName <> Null
            if (Keyword.Trim().Length <= 0)
                return GetUserByRole(RoleName);
            else
            {
                var db = new UserDAL();
                return db.AdminSearch(Keyword, RoleName);
            }
        }

        public static List<User> SearchJobSeekers(String Keyword)
        {
            var db = new UserDAL();
            return db.SearchJobSeekers(Keyword);
        }

        public static List<User> SearchDetailJobSeekers(String Keyword, int JobTypeID, int ExperienceLevelID,
                                                        int EducationLevelID)
        {
            var db = new UserDAL();
            return db.SearchDetailJobSeekers(Keyword, JobTypeID, ExperienceLevelID, EducationLevelID);
        }

        // Update ImageUrl
        public static Boolean UpdateImageUrl(String ImageUrl, String UserID)
        {
            var db = new UserDAL();
            return db.UpdateImageUrl(ImageUrl, UserID);
        }

        // Get First Name
        public static String GetFirstNameByUserID(String UserID)
        {
            User obj = GetUserByID(UserID);
            return obj.FirstName;
        }

        // Get Last Name
        public static String GetLastNameByUserID(String UserID)
        {
            User obj = GetUserByID(UserID);
            return obj.LastName;
        }

        // Get Address
        public static String GetAddressByUserID(String UserID)
        {
            User obj = GetUserByID(UserID);
            return obj.Address;
        }

        public static String GetCompanyByUserID(String UserID)
        {
            try
            {
                User obj = GetUserByID(UserID);
                return obj.Company;
            }
            catch
            {
                return "";
            }
        }

        public static String GetUserIDByUserName(String UserName)
        {
            var db = new UserDAL();
            return db.GetUserIDByUserName(UserName);
        }

        public static String GetUserNameByUserID(String UserID)
        {
            var db = new UserDAL();
            return db.GetUserNameByUserID(UserID);
        }

        public static Boolean Approved(String Email)
        {
            var db = new UserDAL();
            return db.Approved(Email);
        }

        //*****************************************************************************
        public static int Insert(User obj)
        {
            var db = new UserDAL();
            return db.Insert(obj);
        }

        public static bool Update(User obj)
        {
            var db = new UserDAL();
            return db.Update(obj);
        }

        public static bool Delete(String UserID)
        {
            var db = new UserDAL();
            return db.Delete(UserID);
        }

        public static User GetUserByID(String UserID)
        {
            var db = new UserDAL();
            return db.GetUserByID(UserID);
        }

        //Get All User
        public static List<User> GetAllUser()
        {
            var db = new UserDAL();
            return db.GetAllUser(1, MAXROWS);
        }

        //Get All User
        public static List<User> GetAllUser(int PageIndex, int PageSize)
        {
            var db = new UserDAL();
            return db.GetAllUser(PageIndex, PageSize);
        }

        // Get Count All records of Table  User
        public static int GetCountUser()
        {
            var db = new UserDAL();
            return db.GetCountUser();
        }

        public static String[] GetUsersInRole(string Role)
        {
            return Roles.GetUsersInRole(Role);
        }

        //Get User By Role
        public static List<User> GetUserByRole(String Role)
        {
            var db = new UserDAL();
            return db.GetUserByRole(Role);
        }

        #endregion
    }
}